package com.wm;

import com.wm.bean.Person;
import com.wm.config.MainConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @ClassName: MainTest
 * @Description: 测试对象注入到IOC容器中
 * @Author: Deamer
 * @Date: 2022/9/4 21:17
 */
public class MainTest {
    public static void main(String[] args) {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        Person person = applicationContext.getBean(Person.class);
        System.out.println(person);

        // Person这个类型的组件在IOC容器中的名字是什么呢？
        String[] nameForType = applicationContext.getBeanNamesForType(Person.class);
        for (String name : nameForType) {
            System.out.printf(name);
        }
    }

    // 测试使用xml的方式将对象注入到IOC容器中
    private static void xmlIntoIOC() {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
        Person person = (Person) applicationContext.getBean("person");
    }
}
